package com.example.multi_media_demo.ui.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.multi_media_demo.R;
import com.example.multi_media_demo.databinding.FragmentHomeBinding;
import com.example.multi_media_demo.surfaceview.video.SurfaceVideoActivity;
import com.example.multi_media_demo.surfaceview.view.SurfaceViewHandWritingActivity;
import com.example.multi_media_demo.surfaceview.view.SurfaceViewSinActivity;

public class HomeFragment extends Fragment implements View.OnClickListener {

    private HomeViewModel homeViewModel;
    private FragmentHomeBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        //===
        homeViewModel =
                new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(HomeViewModel.class);
        //===
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        //===
        initData();
        //===
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    private void initData() {
        binding.btSVSinFun.setOnClickListener(this);
        binding.btSVHandWriting.setOnClickListener(this);
        binding.btSVVideo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btSVSinFun: {
                startActivity(new Intent(getActivity(), SurfaceViewSinActivity.class));
                break;
            }
            case R.id.btSVHandWriting: {
                startActivity(new Intent(getActivity(), SurfaceViewHandWritingActivity.class));
                break;
            }
            case R.id.btSVVideo: {
                startActivity(new Intent(getActivity(), SurfaceVideoActivity.class));
                break;
            }
        }
    }
}